package com.soft.admin.login.action;

import javax.annotation.Resource;

import com.soft.admin.login.service.ILoginService;
import com.soft.mapping.User;
import com.soft.util.Handle;
import com.soft.util.MyActionSupport;

public class AdminLoginAction extends MyActionSupport {

	@Resource
	private ILoginService iLoginService;

	@Override
	public String execute() throws Exception {
		return super.execute();
	}

	/**
	 * 登录
	 * 
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public String login() throws Exception {
		String uname = Handle.trim(request.getParameter("uname"));
		String upwd = Handle.trim(request.getParameter("upwd"));
		User user = iLoginService.getUser(uname, upwd);
		// System.out.println(uname + " " + upwd + " " + user);
		if (user != null) {
			map.put("user", user);
		} else {
			map.put("login", "error");
		}
		return SUCCESS;
	}

	/**
	 * 登出
	 * 
	 * @return
	 * @throws Exception
	 */
	public String logout() throws Exception {
		map.remove("user");
		map.remove("login");
		return SUCCESS;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

}
